<script setup lang="ts">
import {computed} from "vue";

const props = defineProps({
  component: {type: Object},
  crudForm: {type: Object},
  type: {type: String},
})
const options = computed(() => {
  if (!currentService.value) return [];
  let service_radio = currentService.value[props.type].toString();
  return props.crudForm?.getColumnService().getDictService(props.type).dictData.filter(i => {
    return service_radio.indexOf(i.value) !== -1
  })
})
const currentService = computed(() => {
  let serviceDict = props.crudForm?.getColumnService().getDictService('service_id').dictData
  if (!serviceDict) {
    return undefined;
  }
  let currentServiceId = props.crudForm?.getFormData()['service_id']
  let service
  serviceDict.map(i => {
    if (currentServiceId === i.value) {
      service = i.data
    }
  })
  return service
})
</script>

<template>
  <a-radio-group :size="component.size" :direction="component.direction" :type="component.type"
                 :disabled="component.disabled" v-model="props.crudForm.getFormData()[type]">
    <template v-for="(item, index) in (options ?? [])">
      <a-radio :value="item.value" :disabled="item.disabled">{{ item.label }}</a-radio>
    </template>
  </a-radio-group>
</template>

<style scoped>

</style>